<?php

use common\helpers\Html;
use yii\grid\GridView;
use kartik\daterange\DateRangePicker;

$this->title = '请假管理';
$this->params['breadcrumbs'][] = $this->title;

?>

<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title"><?= Html::encode($this->title) ?></h3>
                <div class="box-tools">
                    <?= Html::create(['export'], '导出',['target'=>'_blank']); ?>
                    <?= Html::create(['cate/index'], '分类'); ?>
                    <?= Html::create(['create'], '创建'); ?>
                </div>
            </div>
            <div class="box-body table-responsive">
                <?= GridView::widget([
                    'dataProvider' => $dataProvider,
                    'filterModel' => $searchModel,
                    'tableOptions' => [
                        'class' => 'table table-hover rf-table',
                        'fixedNumber' => 1,
                        'fixedRightNumber' => 1,
                    ],
                    'columns' => [
                        [
                            'attribute' => 'cate_id',
                            'value' => 'cate.title',
                            'filter' => Html::activeDropDownList($searchModel, 'cate_id', $cates, [
                                    'prompt' => '全部',
                                    'class' => 'form-control'
                                ]
                            )
                        ],
                        'content',
                        'num',
                        [
                            'attribute' => 'member.realname',
                            'filter' => Html::activeTextInput($searchModel, 'member.realname', [
                                    'class' => 'form-control'
                                ]
                            ),
                            'headerOptions' => ['class' => 'col-md-1'],
                        ],

                        [
                            'attribute' => 'created_at',
                            'filter' => DateRangePicker::widget([
                                'name' => 'SearchModel[created_at]',
                                'value' => Yii::$app->request->get('SearchModel')['created_at'],
                                'convertFormat' => true,
                                'pluginOptions' => [
                                    'locale' => [
                                        'format' => 'Y-m-d',
                                        'separator' => '/',
                                    ],
                                ]
                            ]),
                            'value'=>function($model){
                                return date("Y-m-d H:i:s",$model->created_at);
                            },
                        ],
                        [
                            'attribute' => 'state',
                            'value' => function ($model) {
                                $status=true;
                                foreach ($model->getNextStatuses() as $key => $nextStatus) {
                                    $status = false;
                                }
                                if($status) return $model->getWorkflowStatus()->getLabel();
                                if(!$status) return \addons\Flow\common\enums\WorkflowEnum::getValue($model->state);
                            },
                            'filter' => Html::activeDropDownList($searchModel, 'state', \addons\Flow\common\enums\WorkflowEnum::getMap(), [
                                    'prompt' => '全部',
                                    'class' => 'form-control'
                                ]
                            )
                        ],

                        [
                            'class' => 'yii\grid\ActionColumn',
                            'header' => '操作',
                            'headerOptions' => ['width' => '250'],
                            'template' => '{approve} {edit} {delete}',
                            'buttons' => [
                                'approve' => function ($url, $model, $key) {
                                    return Html::edit(['ajax-approve', 'id' => $model->id], '进度', [
                                        'class' => 'btn btn-warning btn-sm',
                                        'data-toggle' => 'modal',
                                        'data-target' => '#ajaxModalLg',
                                    ]);
                                },
                                'edit' => function ($url, $model, $key) {
                                    return Html::edit(['edit', 'id' => $model->id], '编辑');
                                },
                                'delete' => function ($url, $model, $key) {
                                    return Html::delete(['delete', 'id' => $model->id]);
                                },
                            ]
                        ]
                    ]
                ]); ?>
            </div>
        </div>
    </div>
</div>
